from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-01-11 14:04:45.355595
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 11, Jan, 2022
Time: 14:04:50
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.6737
Nobs: 533.000 HQIC: -48.1135
Log likelihood: 6180.93 FPE: 9.59015e-22
AIC: -48.3962 Det(Omega_mle): 8.11282e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.393065 0.072217 5.443 0.000
L1.Burgenland 0.099066 0.042937 2.307 0.021
L1.Kärnten -0.113769 0.022157 -5.135 0.000
L1.Niederösterreich 0.179802 0.089371 2.012 0.044
L1.Oberösterreich 0.113752 0.088730 1.282 0.200
L1.Salzburg 0.269881 0.045338 5.953 0.000
L1.Steiermark 0.024436 0.059721 0.409 0.682
L1.Tirol 0.109866 0.048158 2.281 0.023
L1.Vorarlberg -0.078258 0.042563 -1.839 0.066
L1.Wien 0.008186 0.078521 0.104 0.917
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059846 0.158445 0.378 0.706
L1.Burgenland -0.042276 0.094204 -0.449 0.654
L1.Kärnten 0.039867 0.048612 0.820 0.412
L1.Niederösterreich -0.208164 0.196081 -1.062 0.288
L1.Oberösterreich 0.455472 0.194675 2.340 0.019
L1.Salzburg 0.286455 0.099472 2.880 0.004
L1.Steiermark 0.113792 0.131028 0.868 0.385
L1.Tirol 0.306986 0.105659 2.905 0.004
L1.Vorarlberg 0.020062 0.093383 0.215 0.830
L1.Wien -0.022831 0.172275 -0.133 0.895
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.201538 0.036937 5.456 0.000
L1.Burgenland 0.092948 0.021961 4.232 0.000
L1.Kärnten -0.007432 0.011333 -0.656 0.512
L1.Niederösterreich 0.232981 0.045711 5.097 0.000
L1.Oberösterreich 0.162936 0.045383 3.590 0.000
L1.Salzburg 0.040382 0.023189 1.741 0.082
L1.Steiermark 0.025164 0.030545 0.824 0.410
L1.Tirol 0.082621 0.024631 3.354 0.001
L1.Vorarlberg 0.055188 0.021770 2.535 0.011
L1.Wien 0.115141 0.040161 2.867 0.004
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.130233 0.036946 3.525 0.000
L1.Burgenland 0.040300 0.021966 1.835 0.067
L1.Kärnten -0.014596 0.011335 -1.288 0.198
L1.Niederösterreich 0.166989 0.045722 3.652 0.000
L1.Oberösterreich 0.334610 0.045394 7.371 0.000
L1.Salzburg 0.105610 0.023195 4.553 0.000
L1.Steiermark 0.108909 0.030553 3.565 0.000
L1.Tirol 0.092736 0.024637 3.764 0.000
L1.Vorarlberg 0.054959 0.021775 2.524 0.012
L1.Wien -0.020380 0.040171 -0.507 0.612
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.105309 0.070223 1.500 0.134
L1.Burgenland -0.040280 0.041751 -0.965 0.335
L1.Kärnten -0.045889 0.021545 -2.130 0.033
L1.Niederösterreich 0.144899 0.086903 1.667 0.095
L1.Oberösterreich 0.169588 0.086280 1.966 0.049
L1.Salzburg 0.280611 0.044086 6.365 0.000
L1.Steiermark 0.063084 0.058071 1.086 0.277
L1.Tirol 0.155239 0.046828 3.315 0.001
L1.Vorarlberg 0.095254 0.041387 2.302 0.021
L1.Wien 0.076185 0.076352 0.998 0.318
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.099211 0.054517 1.820 0.069
L1.Burgenland 0.019118 0.032413 0.590 0.555
L1.Kärnten 0.051905 0.016726 3.103 0.002
L1.Niederösterreich 0.185532 0.067467 2.750 0.006
L1.Oberösterreich 0.326263 0.066983 4.871 0.000
L1.Salzburg 0.040371 0.034226 1.180 0.238
L1.Steiermark -0.004340 0.045083 -0.096 0.923
L1.Tirol 0.126148 0.036355 3.470 0.001
L1.Vorarlberg 0.063426 0.032131 1.974 0.048
L1.Wien 0.093508 0.059276 1.578 0.115
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.164795 0.066133 2.492 0.013
L1.Burgenland 0.012496 0.039320 0.318 0.751
L1.Kärnten -0.065266 0.020290 -3.217 0.001
L1.Niederösterreich -0.109441 0.081843 -1.337 0.181
L1.Oberösterreich 0.213673 0.081255 2.630 0.009
L1.Salzburg 0.050262 0.041519 1.211 0.226
L1.Steiermark 0.254024 0.054690 4.645 0.000
L1.Tirol 0.498767 0.044101 11.310 0.000
L1.Vorarlberg 0.067140 0.038977 1.723 0.085
L1.Wien -0.082550 0.071906 -1.148 0.251
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.167384 0.073121 2.289 0.022
L1.Burgenland -0.007822 0.043474 -0.180 0.857
L1.Kärnten 0.063279 0.022434 2.821 0.005
L1.Niederösterreich 0.176563 0.090490 1.951 0.051
L1.Oberösterreich -0.066891 0.089841 -0.745 0.457
L1.Salzburg 0.207193 0.045906 4.513 0.000
L1.Steiermark 0.136082 0.060468 2.250 0.024
L1.Tirol 0.054537 0.048761 1.118 0.263
L1.Vorarlberg 0.144628 0.043096 3.356 0.001
L1.Wien 0.127915 0.079503 1.609 0.108
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.407791 0.042649 9.561 0.000
L1.Burgenland -0.004777 0.025357 -0.188 0.851
L1.Kärnten -0.020828 0.013085 -1.592 0.111
L1.Niederösterreich 0.197884 0.052780 3.749 0.000
L1.Oberösterreich 0.238753 0.052401 4.556 0.000
L1.Salzburg 0.037338 0.026775 1.395 0.163
L1.Steiermark -0.019927 0.035269 -0.565 0.572
L1.Tirol 0.089060 0.028441 3.131 0.002
L1.Vorarlberg 0.049805 0.025136 1.981 0.048
L1.Wien 0.028314 0.046372 0.611 0.541
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.033058 0.094312 0.158507 0.137516 0.080953 0.079861 0.025061 0.203550
Kärnten 0.033058 1.000000 -0.028037 0.132496 0.047448 0.083223 0.447127 -0.071078 0.093250
Niederösterreich 0.094312 -0.028037 1.000000 0.307791 0.125580 0.262705 0.063467 0.153602 0.277181
Oberösterreich 0.158507 0.132496 0.307791 1.000000 0.217002 0.289844 0.169143 0.131906 0.228314
Salzburg 0.137516 0.047448 0.125580 0.217002 1.000000 0.125574 0.082931 0.108271 0.127293
Steiermark 0.080953 0.083223 0.262705 0.289844 0.125574 1.000000 0.135250 0.102131 0.021295
Tirol 0.079861 0.447127 0.063467 0.169143 0.082931 0.135250 1.000000 0.062956 0.148014
Vorarlberg 0.025061 -0.071078 0.153602 0.131906 0.108271 0.102131 0.062956 1.000000 -0.008712
Wien 0.203550 0.093250 0.277181 0.228314 0.127293 0.021295 0.148014 -0.008712 1.000000